/*
 * 
 * Created on Jul 22, 2005
 */
package com.wgo.precise.client.ui.view.util;

import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredViewer;
import org.eclipse.swt.dnd.DragSourceEvent;
import org.eclipse.swt.dnd.DragSourceListener;

import com.wgo.precise.client.ui.model.ClientModelItem;
import com.wgo.precise.client.ui.model.facade.IPropertiesContainer;


/**
 * 
 * @author Petter L. H. Eide
 * @version $Id: ModelItemDragSourceListener.java,v 1.1 2006-01-23 19:58:37 petterei Exp $
 * 
 */
public class ModelItemDragSourceListener implements DragSourceListener {

    private StructuredViewer viewer;

    public ModelItemDragSourceListener(StructuredViewer viewer) {
       this.viewer = viewer;
    }

    IPropertiesContainer dragData;
    
    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragStart(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragStart(DragSourceEvent event) {
        Object o = ((IStructuredSelection)viewer.getSelection()).getFirstElement();
//        System.out.println("Type: " + o.getClass().getName());
        event.doit = !viewer.getSelection().isEmpty() &&  o instanceof ClientModelItem;
        if (event.doit) {
            dragData = (IPropertiesContainer) o ;
        }
    }

    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragSetData(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragSetData(DragSourceEvent event) {
        event.data = dragData;
    }

    /**
     * @see org.eclipse.swt.dnd.DragSourceListener#dragFinished(org.eclipse.swt.dnd.DragSourceEvent)
     */
    public void dragFinished(DragSourceEvent event) {
        if (!event.doit) {
            return;
        }
    }
    
}
/**
 * 
 * Changelog:
 * 
 * $Log: ModelItemDragSourceListener.java,v $
 * Revision 1.1  2006-01-23 19:58:37  petterei
 * initial commit for client, fitting the alternative session implementation
 *
 * Revision 1.2  2005-12-05 04:16:40  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/10/11 15:08:03  petterei
 * Seccond iteration:
 * 1. Eclipse based client with new domain model
 * 2. Flexible Project and Category hierarchy with Drag-n-Drop functionality
 * New functionality:
 * 3. Eclipse plugin update-site
 *
 * Revision 1.2  2005/09/27 17:06:19  petterei
 * *** empty log message ***
 *
 * Revision 1.1  2005/08/28 18:01:26  peide3
 * save in Eclipse-way
 * dynamic propertyspecifications bug fixed
 * dnd to deside order of property specification
 * ItemType to make convertion more understandable
 *
 *
 */
